//package com.qujia.station.service.impl;
//
//import cn.hutool.core.date.DateUtil;
//import com.qujia.common.core.redis.RedisCache;
//import com.qujia.common.enums.PayTypeEnum;
//import com.qujia.common.enums.RechargeTypeEnum;
//import com.qujia.common.utils.MathUtil;
//import com.qujia.customer.enums.CardRecordType;
//import com.qujia.station.domain.ClassSettlement;
//import com.qujia.station.domain.ClassSettlementCard;
//import com.qujia.station.domain.Station;
//import com.qujia.station.domain.StationDeviceManage;
//import com.qujia.station.domain.dto.CardClassSettDto;
//import com.qujia.station.enums.PrintEnum;
//import com.qujia.station.service.*;
//import com.qujia.station.utils.FeiEPrinterUtil;
//import com.qujia.station.utils.Methods;
//import lombok.extern.slf4j.Slf4j;
//import org.apache.commons.collections.CollectionUtils;
//import org.apache.commons.lang3.StringUtils;
//import org.json.JSONObject;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.scheduling.annotation.Async;
//import org.springframework.stereotype.Service;
//
//import javax.annotation.Resource;
//import java.math.BigDecimal;
//import java.math.RoundingMode;
//import java.text.SimpleDateFormat;
//import java.util.*;
//import java.util.concurrent.TimeUnit;
//import java.util.stream.Collectors;
//
//@Slf4j
//@Service
//public class ClassSettlementPrintServiceImpl implements ClassSettlementPrintService {
//
//
//    @Resource
//    private IClassSettlementService classSettlementService;
//
//    @Resource
//    private ClassSettlementCardService classSettlementCardService;
//
//    @Resource
//    private IStationService stationService;
//
//    @Resource
//    private IStationDeviceManageService stationDeviceManageService;
//
//    @Autowired
//    private RedisCache redisCache;
//
//    @Override
//    @Async("threadPoolTaskExecutor")
//    public void getPushMessage(ClassSettlement classSettlement) throws InterruptedException {
//        // 防止事务未提交导致查询不到
//        Thread.sleep(3000);
//        SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        Map<String, Object> queryMap = new HashMap<>();
//        queryMap.put("stationId", classSettlement.getStationId());
//        queryMap.put("classNo", classSettlement.getClassNo());
//        log.info("queryMap==={}",queryMap);
//        //合计所有油品信息的集合
//        List<ClassSettlement> sumOilList = classSettlementService.queryClassSettlementOil(queryMap);
//        log.info("sumOilList{}",sumOilList);
//        //合计班结信息，按照支付方式的集合
//        List<ClassSettlement> sumPayTypeList = classSettlementService.queryClassSettlementPayType(queryMap);
//
//        ClassSettlementCard classSettlementCard = new ClassSettlementCard();
//        classSettlementCard.setClassNo(classSettlement.getClassNo());
//        //合计班结信息，充值的信息集合
//        List<ClassSettlementCard> sumCzList = classSettlementCardService.queryGroupByCardType(classSettlementCard);
//        //合计  班结总计的信息集合
////        List<ClassSettlement> sumClassList = classSettlementService.querySummaryByClassNo(queryMap);
//
//
//        //加油员班结信息汇总
//        List<ClassSettlement> oilPersonList = classSettlementService.selectClassSettlementSummaryUser(queryMap);
//        //充值金额合计
//        ClassSettlementCard classSettlementCardCz = classSettlementCardService.querySumCz(queryMap);
//
//        //退款信息
//        ClassSettlementCard form = new ClassSettlementCard();
//        form.setClassNo(classSettlement.getClassNo());
//        List<ClassSettlementCard> classSettlementCards = classSettlementCardService.selectClassSettlementCardList(form);
//
//        CardClassSettDto settDto = countCardSett(classSettlementCards); //电子卡交易汇总数据
//        List<ClassSettlement> sumClassList = classSettlementService.querySummaryByClassNoAllData(queryMap,settDto);
//        Map<String, Object> params = new HashMap<String, Object>();
//        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//        if (classSettlement.getClassStartTime() != null) {
//            String classStartTime = dateFormat.format(classSettlement.getClassStartTime());
//            params.put("createStartTime", classStartTime);
//        }
//
//        params.put("createEndTime", dateFormat.format(classSettlement.getClassEndTime()));
//        params.put("stationId", classSettlement.getStationId());
//        List<ClassSettlement> refundSummary = classSettlementService.getRefundSummary(settDto, params);
//        //充值汇总统计
//        List<ClassSettlementCard> transactionSummary = classSettlementService.getTransactionSummary(settDto, params);
//        List<Map<String, Object>> queryGroupByPayType = classSettlementService.queryGroupByPayType(queryMap);
//        List<ClassSettlementCard> queryGroupByRecharge = classSettlementService.queryGroupByRecharge(queryGroupByPayType,settDto);
//
//        List<Map<String, Object>> oilPersonClass = new ArrayList<>();
//        for (int i = 0; i < oilPersonList.size(); i++) {
//            Map<String, Object> person1 = new HashMap<>();
//            person1.put("personName", oilPersonList.get(i).getOilPersonnelName());
//            if (classSettlement.getClassStartTime() == null) {
//                person1.put("classStartTime", "首次");
//            } else {
//                person1.put("classStartTime", fmt.format(classSettlement.getClassStartTime()));
//            }
//            person1.put("classEndTime", fmt.format(classSettlement.getClassEndTime()));
//            Map<String, Object> queryMap1 = new HashMap<>();
//            queryMap1.put("stationId", classSettlement.getStationId());
//            queryMap1.put("classNo", classSettlement.getClassNo());
//            queryMap1.put("oilPersonnelId", oilPersonList.get(i).getOilPersonnelId());
//            //合计所有油品信息的集合
//            List<ClassSettlement> OilList = classSettlementService.queryClassSettlementOil(queryMap);
//            person1.put("oilList", OilList);
//            person1.put("orderCount", oilPersonList.get(i).getOrderCount());
//            person1.put("receivableAmt", oilPersonList.get(i).getReceivableAmt());
//            person1.put("discountAmt", oilPersonList.get(i).getDiscountAmt());
//            person1.put("refundAmt", oilPersonList.get(i).getRefundAmt());
//            person1.put("amt", oilPersonList.get(i).getAmt());
//            person1.put("oilPersonnelName", oilPersonList.get(i).getOilPersonnelName());
//            oilPersonClass.add(person1);
//        }
//        Map<String, Object> sumClassMap = new HashMap<>();
//        sumClassMap.put("sumClassList", sumClassList);
//        sumClassMap.put("sumOilList", sumOilList);
//        sumClassMap.put("sumPayTypeList", sumPayTypeList);
//        sumClassMap.put("sumCzList", sumCzList);
//        sumClassMap.put("oilPersonClass", oilPersonClass);
//
//
//        //员工汇总
//
//        List<Map<String, Object>> listDetail4User = classSettlementService.selectClassSettlement4User4POSList(queryMap);
//
//
//        this.feiePush(sumClassList, sumOilList, sumPayTypeList, sumCzList, oilPersonClass, classSettlementCardCz,classSettlement,refundSummary, listDetail4User, transactionSummary, queryGroupByRecharge);
//
//    }
//
//    // 打印的班结小票的排版
//    public void feiePush(List<ClassSettlement> sumClassList, List<ClassSettlement> sumOilList, List<ClassSettlement> sumPayTypeList, List<ClassSettlementCard> sumCzList, List<Map<String, Object>> oilPersonList, ClassSettlementCard czClass,ClassSettlement classSettlement, List<ClassSettlement> refundSummary,List<Map<String, Object>> listDetail4User,List<ClassSettlementCard> transactionSummary, List<ClassSettlementCard> queryGroupByRecharge) { //
//        try {
//            if (sumClassList == null || sumClassList.size() <= 0) {
//                return;
//            }
//            Station station = stationService.selectStationById(sumClassList.get(0).getStationId());
//
//            StationDeviceManage stationDeviceManage = new StationDeviceManage();
//            stationDeviceManage.setStationId(sumClassList.get(0).getStationId());
//            stationDeviceManage.setDeviceType("3");
//            List<StationDeviceManage> stationDeviceManages = stationDeviceManageService.selectStationDeviceManageList(stationDeviceManage);
//            if (stationDeviceManages == null || stationDeviceManages.size() <= 0) {
//                return;
//            }
//            StringBuilder content = new StringBuilder();
//            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//            if (true) {
//                content.append("<BOLD><B>--班结小票----</B></BOLD><BR>");
//                if (sumClassList.get(0).getClassStartTime() != null) {
//                    content.append("接班时间：" + sdf.format(sumClassList.get(0).getClassStartTime()) + "<BR>");
//                } else {
//                    content.append("接班时间：" + "首次" + "<BR>");
//                }
//                if (sumClassList.get(0).getClassEndTime() != null) {
//                    content.append("交班时间：" + sdf.format(sumClassList.get(0).getClassEndTime()) + "<BR>");
//                }
//                content.append("班结人："+ sumClassList.get(0).getCreateName() + "<BR>");
//                content.append("---------------------------"+ "<BR>");
//
//
//                if (CollectionUtils.isNotEmpty(sumClassList)) {
//                    BigDecimal receivableAmt  = sumClassList.get(0).getReceivableAmt()!=null?sumClassList.get(0).getReceivableAmt():BigDecimal.ZERO;
//                    content.append("消费应收总金额：" +receivableAmt + "元<BR>");
//                }
//
//
//                if (sumClassList.get(0).getDiscountAmt() != null) {
//                    BigDecimal discountAmountAmt =  Objects.isNull(sumClassList.get(0).getDiscountAmt()) ? BigDecimal.ZERO : sumClassList.get(0).getDiscountAmt();
//                    BigDecimal discountCouponAmt =  Objects.isNull(sumClassList.get(0).getDiscountCouponAmt()) ? BigDecimal.ZERO : sumClassList.get(0).getDiscountCouponAmt();
//                    content.append("消费优惠金额：" + discountAmountAmt.add(discountCouponAmt) + "元<BR>");
//                }
//
//                if (sumClassList.get(0).getReceivableAmt() != null) {
//                    content.append("消费实收总金额：" + sumClassList.get(0).getAmt() + "元<BR>");
//                }
//
//                if (CollectionUtils.isNotEmpty(refundSummary)) {
//                    BigDecimal refundSum = refundSummary.stream().filter(m -> !"合计".equals(m.getPayType())).map(ClassSettlement::getRefundAmt).reduce(BigDecimal.ZERO, BigDecimal::add);
//
//                    //充值退款
//                    BigDecimal refRefoundSum = refundSummary.stream().filter(m -> !"合计".equals(m.getPayType()) && "ref".equals(m.getPayType())).map(ClassSettlement::getRefundAmt).reduce(BigDecimal.ZERO, BigDecimal::add);
//                    //消费退款
//                    BigDecimal consumeRefoundSum = refundSum.subtract(refRefoundSum);
//                    //充值退款
//
//                    content.append("退款总金额:(消费退款+充值退款):<BR>" + "(" + consumeRefoundSum + "+" + refRefoundSum + ")" + refundSum  + "元<BR>");
//                }
//
//                //平台储值合计
////                if(!CollectionUtils.isEmpty(sumCzList)){
//                content.append("平台储值合计（电子卡+实体卡+车队卡）：" );
//                BigDecimal dzkAmk = BigDecimal.ZERO;
//                BigDecimal dkqAmt = BigDecimal.ZERO;
//                BigDecimal cdkAmt = BigDecimal.ZERO;
//                //电子卡手动充值金额
//                BigDecimal handRecharge = BigDecimal.ZERO;
//                for (ClassSettlementCard classSettlementCard : transactionSummary) {
//                    if(RechargeTypeEnum.imp.getType().equals(classSettlementCard.getPayType())){
//                        handRecharge = handRecharge.add(Objects.isNull(classSettlementCard.getAmt()) ? BigDecimal.ZERO : classSettlementCard.getAmt());
//                    }
//                    if(RechargeTypeEnum.pos.getType().equals(classSettlementCard.getPayType())){
//                        handRecharge = handRecharge.add(Objects.isNull(classSettlementCard.getAmt()) ? BigDecimal.ZERO : classSettlementCard.getAmt());
//                    }
//                    if(RechargeTypeEnum.wx.getType().equals(classSettlementCard.getPayType())){
//                        handRecharge = handRecharge.add(Objects.isNull(classSettlementCard.getAmt()) ? BigDecimal.ZERO : classSettlementCard.getAmt());
//                    }
//                }
//
//                //车队卡储值
//                BigDecimal handCdkRecharge = BigDecimal.ZERO;
//                for (ClassSettlementCard classSettlementCard : transactionSummary) {
//                    if(RechargeTypeEnum.cdk.getType().equals(classSettlementCard.getPayType())){
//                        handCdkRecharge = Objects.isNull(classSettlementCard.getAmt()) ? BigDecimal.ZERO : classSettlementCard.getAmt();
//                    }
//                }
//
//                BigDecimal handDkqRecharge = BigDecimal.ZERO;
//                for (ClassSettlementCard classSettlementCard : transactionSummary) {
//                    if(RechargeTypeEnum.dkq.getType().equals(classSettlementCard.getPayType())){
//                        handDkqRecharge = Objects.isNull(classSettlementCard.getAmt()) ? BigDecimal.ZERO : classSettlementCard.getAmt();
//                    }
//                }
//                dzkAmk = handRecharge;
//                for (ClassSettlementCard classSettlementCard : sumCzList) {
//                    if(StringUtils.isEmpty(classSettlementCard.getRechargeType())){
//                        continue;
//                    }
//                    String des = "";
//                    if(!StringUtils.isEmpty(classSettlementCard.getRechargeType())){
//                        if (PayTypeEnum.dkq == PayTypeEnum.getByType(classSettlementCard.getRechargeType())) {
//                            dkqAmt =  classSettlementCard.getAmt();
//                        } else if(PayTypeEnum.cdk == PayTypeEnum.getByType(classSettlementCard.getRechargeType())){
//                            cdkAmt =  classSettlementCard.getAmt();
//                        }
//                    }
//
////                        content.append(des + "     " + classSettlementCard.getOrderCount() + "     " + classSettlementCard.getAmt() + "<BR>");
//
//                }
//                content.append( "(" + dzkAmk + "元 + " + handDkqRecharge + "元 + " + handCdkRecharge + "元)" + dzkAmk.add(handDkqRecharge).add(handCdkRecharge) + ("元") + "<BR>");
////                }
//                BigDecimal sumOrderCount = sumOilList.stream().filter(cs -> Objects.nonNull(cs.getOrderLiters())).map(ClassSettlement::getOrderLiters).reduce(BigDecimal.ZERO, BigDecimal::add);
//                content.append("合计销售数量：" + sumOrderCount + "L/kg<BR>");
//
//                BigDecimal consumeReceived  = Objects.isNull(sumClassList.get(0).getAmt()) ? BigDecimal.ZERO : sumClassList.get(0).getAmt();
//                BigDecimal actualRechargeReceivedAmt = Objects.isNull(sumClassList.get(0).getActualRechargeReceivedAmt()) ? BigDecimal.ZERO : sumClassList.get(0).getActualRechargeReceivedAmt();
//
////                content.append("到账总金额：" + consumeReceived.add(actualRechargeReceivedAmt)  + "元<BR>");
//                content.append("到账总金额：" + sumClassList.get(0).getTotalWithdrawalAmount().setScale(2,RoundingMode.HALF_DOWN)  + "元<BR>");
//
//
//                content.append("--------------------------" + "<BR>");
//                content.append("收款明细" + "<BR>");
//                content.append("支付方式    笔数     金额(元)" + "<BR>");
//                for (ClassSettlement classSettlement1 : sumPayTypeList) {
//                    if(StringUtils.isEmpty(classSettlement1.getPayType())){
//                        continue;
//                    }
//                    content.append(PayTypeEnum.getByType(classSettlement1.getPayType()).getDes() + "    " + padCountString(String.valueOf(classSettlement1.getOrderCount())) + "    " + classSettlement1.getAmt().setScale(2, RoundingMode.HALF_DOWN) + "<BR>");
//                }
//                content.append("--------------------------" + "<BR>");
//                content.append("充值汇总" + "<BR>");
//                content.append("充值类型    笔数     金额(元)" + "<BR>");
//                if(!CollectionUtils.isEmpty(transactionSummary)){
//                    for (ClassSettlementCard classSettlementCard : transactionSummary) {
//                        if("合计".equals(classSettlementCard.getPayType().toString())|| Objects.isNull(classSettlementCard.getAmt()) || BigDecimal.ZERO.compareTo(classSettlementCard.getAmt()) == 0){
//                            continue;
//                        }
//                        BigDecimal rechargeAmt = Objects.nonNull(classSettlementCard.getAmt()) ? classSettlementCard.getAmt() : BigDecimal.ZERO;
//                        content.append(RechargeTypeEnum.getByType(classSettlementCard.getPayType()).getDes() + "    " + padCountString(classSettlementCard.getOrderCount().toString()) + "    " + rechargeAmt.toString() + "<BR>");
//                    }
//                }
//                content.append("--------------------------" + "<BR>");
//
//                content.append("会员卡-交易汇总" + "<BR>");
//                content.append("消费类型    笔数     实收(元)" + "<BR>");
//
//                if(!CollectionUtils.isEmpty(queryGroupByRecharge)){
//                    for (ClassSettlementCard classSettlementCard : queryGroupByRecharge) {
//                        content.append(CardRecordType.getByKey(classSettlementCard.getPayType()).getName() + "    " + padCountString(classSettlementCard.getOrderCount().toString()) + "    " + classSettlementCard.getAmt().toString() + "<BR>");
//                    }
//                }
//
//
//                content.append("--------------------------" + "<BR>");
//                content.append("油品汇总" + "<BR>");
//
//                content.append("油品       笔数     金额(元)" + "<BR>");
//
//
//                for (ClassSettlement classSettlement1 : sumOilList) {
//                    if(StringUtils.isEmpty(classSettlement1.getOilName())){
//                        continue;
//                    }
//                    content.append(padCountOilNameString(classSettlement1.getOilName()) + "        " + padCountString(classSettlement1.getOrderCount().toString()) + "    " + classSettlement1.getAmt() + "<BR>");
//                }
//                content.append("--------------------------" + "<BR>");
//                content.append("员工汇总" + "<BR>");
//                content.append("员工名称   笔数     金额(元)" + "<BR>");
//
//                //员工汇总
//                // 根据活动分组查询统计信息
//                Map<String, List<Map<String, Object>>> oilPersonnelNameMap = listDetail4User.stream().filter(m -> !"合计".equals(m.get("oil_personnel_name"))).collect(Collectors.groupingBy((m -> (String) m.get("oil_personnel_name"))));
//                for (Map.Entry<String, List<Map<String, Object>>> entry : oilPersonnelNameMap.entrySet()) {
//                    String oilPersonnelName = entry.getKey();
//                    List<Map<String, Object>> value = entry.getValue();
//                    //笔数
//                    Integer orderCount = value.stream().mapToInt(map -> ((Number) map.get("order_count")).intValue()).sum();
//                    //金额
//                    Double amt = value.stream().mapToDouble(map -> ((Number) map.get("amt")).doubleValue()).sum();
//
//                    if(StringUtils.isNotBlank(oilPersonnelName) && oilPersonnelName.length() > 5){
//                        oilPersonnelName = oilPersonnelName.substring(0,5);
//                    }
//
//                    content.append(padCountString(oilPersonnelName) + "      " + padCountString(orderCount.toString()) + "    " + new BigDecimal(amt).setScale(2,RoundingMode.HALF_DOWN) + "<BR>");
//                }
//
////                if (sumClassList.get(0).getOrderCount() != null) {
////                    content.append("小票张数：" + sumClassList.get(0).getOrderCount() + "<BR>");
////                }
//
//
////                if (sumClassList.get(0).getAmt() != null) {
////                    content.append("订单实收金额：" + sumClassList.get(0).getAmt() + "<BR>");
////                }
////                if (czClass != null && czClass.getAmt() != null) {
////                    content.append("充值金额：" + czClass.getAmt() + "<BR>");
////                }
//
////                if( czClass!=null&&czClass.getAmt() != null&&sumClassList.get(0).getAmt()!=null){
////                    content.append("订单充值合计：" + sumClassList.get(0).getAmt().add(czClass.getAmt())+ "<BR>");
////                }else if(sumClassList.get(0).getAmt()!=null) {
////                    content.append("订单充值合计：" + sumClassList.get(0).getAmt()+ "<BR>");
////                }else if(czClass!=null&&czClass.getAmt()!=null){
////                    content.append("订单充值合计：" + czClass.getAmt()+ "<BR>");
////                }
//
//
//                content.append("-------------------------<BR>");
//                content.append("打印时间： " + DateUtil.now() + "<BR>");
//                content.append("<BR>");
//                content.append("<BR>");
//                content.append("<BR>");
//                Boolean personFlage = false;
//                if (station != null && station.getClassPersonFlag() != null && station.getClassPersonFlag().equals("1")) {
//                    for (Map<String, Object> oilPerson : oilPersonList) {
//                        content.append("<BOLD><B>-班结小票---" + oilPerson.get("oilPersonnelName") + "-</B></BOLD><BR>");
//                        if (sumClassList.get(0).getClassStartTime() != null) {
//                            content.append("开始时间：" + sdf.format(sumClassList.get(0).getClassStartTime()) + "<BR>");
//                        } else {
//                            content.append("开始时间：" + "首次" + "<BR>");
//                        }
//                        if (sumClassList.get(0).getClassEndTime() != null) {
//                            content.append("结束时间：" + sdf.format(sumClassList.get(0).getClassEndTime()) + "<BR>");
//                        }
//                        content.append("油品   笔数    升数     金额" + "<BR>");
//                        content.append("--------------------------" + "<BR>");
//                        List<ClassSettlement> oilList = (List<ClassSettlement>) oilPerson.get("oilList");
//                        for (ClassSettlement classSettlement1 : oilList) {
//                            content.append(classSettlement1.getOilName() + "   " + classSettlement1.getOrderCount() + "    " + classSettlement1.getOrderLiters() + "    " + classSettlement1.getAmt() + "<BR>");
//                        }
//                        content.append("--------------------------" + "<BR>");
//                        if (oilPerson.get("orderCount") != null) {
//                            content.append("小票张数：" + oilPerson.get("orderCount") + "<BR>");
//                        }
//
//                        if (oilPerson.get("receivableAmt") != null) {
//                            content.append("消费金额：" + oilPerson.get("receivableAmt") + "<BR>");
//                        }
//                        if (oilPerson.get("discountAmt") != null) {
//                            content.append("优惠金额：" + oilPerson.get("discountAmt") + "<BR>");
//                        }
//
//                        if (oilPerson.get("refundAmt") != null) {
//                            content.append("退款金额：" + oilPerson.get("refundAmt") + "<BR>");
//                        }
//                        if (oilPerson.get("amt") != null) {
//                            content.append("订单实际支付金额：" + oilPerson.get("amt") + "<BR>");
//                        }
//                        content.append("<BR>");
//                        content.append("<BR>");
//                    }
//                }
//            }
//            content.append("<BR>");
//            content.append("<BR>");
//            StationDeviceManage stationDevice = stationDeviceManages.get(0);
//            String deviceFactory = stationDevice.getDeviceFactory();
//
//            PrintEnum printEnum = PrintEnum.getByCode(deviceFactory);
//            switch (printEnum){
//                case YILIANYUNK4:
//                    String audioK4 = "<VN>8</VN>";
//
//                    String ylyContentK4 = content.toString().replace("<BR>", "\r\n").replace("</B></BOLD>","").replace("<BOLD><B>","");
//                    //初始化控制器类
//                    Methods mK4= Methods.getInstance();
//                    Object tokenK4 = redisCache.getCacheObject("STATION:DEVICE:" + stationDevice.getClientId());
//
//                    Integer random6K4 = (int) ((Math.random() * 9 + 1) * 100000);
//
//                    if(Objects.nonNull(tokenK4)){
//                        String refreshTokenK4 = mK4.getFreedomToken();
//                        String printK4 = mK4.print(stationDevice.getDeviceNo(),audioK4 + ylyContentK4.toString(), random6K4.toString());
//                        log.info("小票机返回值{}",printK4);
//                        JSONObject json = new JSONObject(printK4);
//                        if("0".equals(json.getString("error"))){
//                            break;
//                        }
//                    }
//
//                    //初始化终端信息
//                    mK4.init(stationDevice.getClientId(), stationDevice.getClientSecret());
//                    //获取token
//                    String refreshTokenK4 = mK4.getFreedomToken();
//                    //存入redis
//                    redisCache.setCacheObject("STATION:DEVICE:" + stationDevice.getClientId(),refreshTokenK4,30, TimeUnit.DAYS);
//
//
//                    String printK4 = mK4.print(stationDevice.getDeviceNo(), audioK4 + ylyContentK4, random6K4.toString());
//                    log.info("小票机返回值2{}",printK4);
//
//                    break;
//
//                case YILIANYUN:
//                    String audio = "<audio>班结信息已打印</audio>";
//
//                    String ylyContent = content.toString().replace("<BR>", "\r\n").replace("</B></BOLD>","").replace("<BOLD><B>","");
//                    //初始化控制器类
//                    Methods m= Methods.getInstance();
//                    Object token = redisCache.getCacheObject("STATION:DEVICE:" + stationDevice.getClientId());
//
//                    Integer random6 = (int) ((Math.random() * 9 + 1) * 100000);
//
//                    if(Objects.nonNull(token)){
//                        String refreshToken = m.getFreedomToken();
//                        String print = m.print(stationDevice.getDeviceNo(),audio + ylyContent.toString(), random6.toString());
//                        log.info("小票机返回值{}",print);
//                        JSONObject json = new JSONObject(print);
//                        if("0".equals(json.getString("error"))){
//                            break;
//                        }
//                    }
//
//                    //初始化终端信息
//                    m.init(stationDevice.getClientId(), stationDevice.getClientSecret());
//                    //获取token
//                    String refreshToken = m.getFreedomToken();
//                    //存入redis
//                    redisCache.setCacheObject("STATION:DEVICE:" + stationDevice.getClientId(),refreshToken,30, TimeUnit.DAYS);
//
//
//                    String print = m.print(stationDevice.getDeviceNo(), audio + ylyContent, random6.toString());
//                    log.info("小票机返回值2{}",print);
//                    break;
//                case FEIE:
//                    FeiEPrinterUtil.printReceipt(stationDeviceManages.get(0).getDeviceNo(), content.toString());
//                    break;
//            }
//            //修改小票打印状态
//            classSettlementService.updateClassSettlementPrintStatus(classSettlement.getClassNo());
//
//            return;
//        } catch (Exception e) {
//            log.error(">pushConsumeToUser", e);
//            return;
//        }
//
//    }
//
//    private String padCountString(String input) {
//        if(StringUtils.isEmpty(input)){
//            return input;
//        }
//        int length = input.length();
//        if (length >= 5) {
//            return input;
//        } else {
//            StringBuilder paddedString = new StringBuilder(input);
//            for (int i = 0; i < (5 - length); i++) {
//                paddedString.append(" ");
//            }
//            return paddedString.toString();
//        }
//    }
//
//    private String padCountOilNameString(String input) {
//        if(StringUtils.isEmpty(input)){
//            return input;
//        }
//        int length = input.length();
//        if (length >= 4) {
//            return input;
//        } else {
//            StringBuilder paddedString = new StringBuilder(input);
//            for (int i = 0; i < (4 - length); i++) {
//                paddedString.append(" ");
//            }
//            return paddedString.toString();
//        }
//    }
//
//    private CardClassSettDto countCardSett(List<ClassSettlementCard> settlementCardList){
//        Map<CardRecordType,ClassSettlementCard> map = new HashMap<>();
//        // 根据payType进行分组统计
//        for (ClassSettlementCard settlementCard : settlementCardList) {
//            if (!StringUtils.equals("dzk",settlementCard.getRechargeType())) {
//                continue;
//            }
//            CardRecordType payType = CardRecordType.getByKey(settlementCard.getPayType(),CardRecordType.CONSUME);
//            ClassSettlementCard settlement = map.get(payType);
//            if (settlement == null) {
//                settlement = new ClassSettlementCard();
//                settlement.setPayType(payType.getKey());
//                settlement.setAmt(BigDecimal.ZERO);
//                settlement.setOrderCount(0L);
//                settlement.setServiceCharge(BigDecimal.ZERO);
//                settlement.setGiveAmt(BigDecimal.ZERO);
//                map.put(payType,settlement);
//            }
//            settlement.setAmt(MathUtil.add(settlement.getAmt(),settlementCard.getAmt()));
//            settlement.setOrderCount(MathUtil.add(settlement.getOrderCount(),settlementCard.getOrderCount()));
//            settlement.setServiceCharge(MathUtil.add(settlement.getServiceCharge(),settlementCard.getServiceCharge()==null?null:settlementCard.getServiceCharge().setScale(2, RoundingMode.HALF_UP)));
//            settlement.setGiveAmt(MathUtil.add(settlement.getGiveAmt(),settlementCard.getGiveAmt()));
//        }
//        CardClassSettDto settDto = new CardClassSettDto();// 每个payType数据相加的总计
//        settDto.setTotalAmt(BigDecimal.ZERO);
//        settDto.setTotalRechargeAmt(BigDecimal.ZERO);
//        settDto.setTotalGiveAmt(BigDecimal.ZERO);
//        settDto.setTotalWithdrawalAmount(BigDecimal.ZERO);
//        settDto.setTotalRefundAmt(BigDecimal.ZERO);
//        settDto.setTotalServiceCharge(BigDecimal.ZERO);
//        ArrayList<ClassSettlementCard> settList = new ArrayList<>(); // 包含所有payType数据的列表
//        // 遍历所有的payType,添加map中没有的类型，并进行总计
//        for (CardRecordType value : CardRecordType.values()) {
//            ClassSettlementCard settlement = map.get(value);
//            if (settlement == null) {
//                settlement = new ClassSettlementCard();
//                settlement.setPayType(value.getKey());
//                settlement.setAmt(BigDecimal.ZERO);
//                settlement.setOrderCount(0L);
//                settlement.setServiceCharge(BigDecimal.ZERO);
//                settlement.setGiveAmt(BigDecimal.ZERO);
//                settlement.setWithdrawalAmount(BigDecimal.ZERO);
//            }
//            settList.add(settlement);
//            settDto.setTotalOrderCount((int) (settDto.getTotalOrderCount()+ settlement.getOrderCount()));
//            switch (value){
////                case MANUAL_ADD:
////                    settDto.setTotalAmt(settDto.getTotalAmt().add(settlement.getAmt()));
////                    break;
////                case MANUAL_SUB:
////                    settlement.setAmt(settlement.getAmt().negate());
////                    settDto.setTotalAmt(settDto.getTotalAmt().add(settlement.getAmt()));
////                    break;
//                case WX_RECHARGE:
//                    settDto.setTotalAmt(settDto.getTotalAmt().add(settlement.getAmt()));
//                    settDto.setTotalGiveAmt(settDto.getTotalGiveAmt().add(settlement.getGiveAmt()));
//                    settlement.setWithdrawalAmount(settlement.getAmt().subtract(settlement.getServiceCharge())); // 充值提现=实收-渠道费
//                    settDto.setTotalWithdrawalAmount(settDto.getTotalWithdrawalAmount().add(settlement.getWithdrawalAmount()));
//                    settDto.setTotalRechargeAmt(settDto.getTotalRechargeAmt().add(settlement.getAmt()));
//                    settDto.setTotalServiceCharge(settDto.getTotalServiceCharge().add(settlement.getServiceCharge()));
//                    settDto.setAmt(settlement.getAmt());
//                    settDto.setOrderCount(settlement.getOrderCount());
//                    break;
////                case CONSUME:
////                    settlement.setAmt(settlement.getAmt().negate());
////                    settDto.setTotalAmt(settDto.getTotalAmt().add(settlement.getAmt()));
////                    break;
//                case REFUND:
//                    settDto.setTotalAmt(settDto.getTotalAmt().subtract(settlement.getAmt()));
//                    settDto.setTotalRefundAmt(settDto.getTotalRefundAmt().add(settlement.getAmt()));
//                    settDto.setTotalGiveAmt(MathUtil.subtract(settDto.getTotalGiveAmt(),settlement.getGiveAmt()));
//                    settlement.setWithdrawalAmount(settlement.getServiceCharge().subtract(settlement.getAmt())); // 退款提现=-(实收-渠道费)，总提现要加上这个值
//                    settDto.setTotalWithdrawalAmount(settDto.getTotalWithdrawalAmount().add(settlement.getWithdrawalAmount()));
//                    settDto.setTotalServiceCharge(MathUtil.subtract(settDto.getTotalServiceCharge(),settlement.getServiceCharge()));
//                    //settlement.setAmt(settlement.getAmt().negate());
//                    break;
//            }
//        }
////        ClassSettlementCard countDto = new ClassSettlementCard();
////        countDto.setPayType("zj");
////        countDto.setAmt(settDto.getTotalAmt());
////        countDto.setOrderCount((long)settDto.getOrderCount());
////        countDto.setWithdrawalAmount(settDto.getTotalWithdrawalAmount());
////        settList.add(countDto);
//        settDto.setSettlementCardList(settList);
//        return settDto;
//    }
//}
